package com.yesorno.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yesorno.constants.Constants;
import com.yesorno.ui.CustomTitleActivity;
import com.yesorno.utils.HttpUtils;

public class PublishTopicActivity extends CustomTitleActivity {
	RegBtnsClickListeners rbc = new RegBtnsClickListeners();

	private Button goBack;
	private Button send;

	private EditText topic_comment_desc;
	private Button publish_topic_addphoto;

	private ImageView publish_topic_logo;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (data != null) {
			String key = data.getStringExtra("publish_topic_img");
			Bitmap bitmap = HttpUtils.getBitmapFromCache(key);
			if (key != null) {
				publish_topic_logo.setImageBitmap(bitmap);
				publish_topic_logo.setVisibility(View.VISIBLE);
			}
		}
	}

	/**
	 * 注册页面按钮的监听类
	 * 
	 * @author samoin
	 * @date 2011-07-06
	 * @version 0.1
	 * 
	 */
	class RegBtnsClickListeners implements OnClickListener {
		@Override
		public void onClick(View v) {
			if (v == goBack) {
				Intent intent = new Intent();
				PublishTopicActivity.this.setResult(RESULT_OK, intent);
				PublishTopicActivity.this.finish();
			}
			if (v == send) {

			}
			if (v == publish_topic_addphoto) {
				Intent intent = new Intent();
				intent.putExtra("desc", topic_comment_desc.getText().toString());
				intent.setClass(PublishTopicActivity.this,
						PhotoMenuActivity.class);
				startActivityForResult(intent, 0);

			}
		}

	}

	@Override
	public void setTitleViews() {
		LinearLayout titleLayout = getTITLE_LAYOUT();
		goBack = CustomTitleActivity.createTitleLeftButton(
				PublishTopicActivity.this, R.string.reg_title_btn_goback,
				Constants.TITLE_BTN_MARGIN1);
		goBack.setOnClickListener(rbc);
		titleLayout.addView((View) goBack.getParent());
		TextView tv = CustomTitleActivity.createTitleDesc(
				PublishTopicActivity.this, R.string.publish_topic_title, 0);
		titleLayout.addView((View) tv.getParent());

		send = CustomTitleActivity.createTitleRightButton(
				PublishTopicActivity.this, R.string.publish_topic_send,
				Constants.TITLE_BTN_MARGIN2);
		send.setOnClickListener(rbc);
		LinearLayout ll = (LinearLayout) send.getParent();
		ll.setGravity(Gravity.RIGHT);
		titleLayout.addView((View) send.getParent());

	}

	@Override
	public void setLayoutId() {
		setContentView(R.layout.publish_topic);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		publish_topic_addphoto = (Button) findViewById(R.id.publish_topic_addphoto);
		publish_topic_addphoto.setOnClickListener(rbc);
		topic_comment_desc = (EditText) findViewById(R.id.personal_message_recall_desc);

		publish_topic_logo = (ImageView) findViewById(R.id.publish_topic_logo);
	}
}
